package com.diandian.backend.product.controller;

import com.diandian.backend.product.service.ProductOfflineInfoSkuService;
import com.diandian.base.boot.starter.response.BaseResult;
import com.diandian.base.boot.starter.util.ResultUtil;
import com.diandian.backend.product.param.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * [商品]线下商品SKU信息表
 */
@RestController
@RequestMapping("/offline/info/sku")
public class ProductOfflineInfoSkuController {

    @Autowired
    private ProductOfflineInfoSkuService iProductOfflineInfoSkuService;

    /**
    * 1. 分页查询 todo
    */
    @PostMapping("/page")
    public BaseResult page(@RequestBody ProductOfflineInfoSkuPageParam param) {
        param.check();
        return ResultUtil.makeResult(iProductOfflineInfoSkuService.page(param.toDTO()));
    }

    /**
     * 2. 查询详情 todo
     */
    @PostMapping("/detail")
    public BaseResult getDetail(@RequestBody ProductOfflineInfoSkuDetailParam param) {
        return ResultUtil.makeResult(iProductOfflineInfoSkuService.getDetail(param.toDTO()));
    }

    /**
     * 3. 根据数据id更新数据 todo
     */
    @PostMapping("/updateById")
    public BaseResult updateById(@RequestBody ProductOfflineInfoSkuUpdateByIdParam param) {
        iProductOfflineInfoSkuService.updateById(param.toDTO());
        return ResultUtil.makeResult();
    }

    /**
     * 4. 根据数据id删除数据 todo
     */
    @PostMapping("/deleteById")
    public BaseResult deleteById(@RequestBody ProductOfflineInfoSkuDeleteByIdParam param) {
        param.check();
        iProductOfflineInfoSkuService.deleteById(param.toDTO());
        return ResultUtil.makeResult();
    }

    /**
     * 5. 新增 todo
     */
    @PostMapping("/add")
    public BaseResult add(@RequestBody ProductOfflineInfoSkuAddParam param) {
        iProductOfflineInfoSkuService.add(param.toDTO());
        return ResultUtil.makeResult();
    }

    /**
     * 列表查询
     */
    @PostMapping("/list")
    public BaseResult list(@RequestBody ProductOfflineInfoSkuListParam param) {
        param.check();
        return ResultUtil.makeResult(iProductOfflineInfoSkuService.getList(param.toDTO()));
    }

}